package 手写filter;

/**
 *
 *
 * 存储要执行的filter和servlet
 * @author chedx
 * @data 2021/3/21 3:11 PM
 */
public class ApplicationFilterChain implements FilterChain {
    private Filter [] filters = new Filter[10];
    private Servlet servlet;

    //总共filter个数
    private int n ;
    // 当前执行到的filter
    private int pos;
    @Override
    public void doFilter() {
        if(pos < n) {
            Filter filter = filters[pos++];
            filter.doFilter(this);
            return;
        }
        servlet.service();
    }

    public void addFilters(Filter filter) {
        this.filters[n++] = filter;
    }

    public void addServlet(Servlet servlet) {
        this.servlet = servlet;
    }
}
